package ar.com.solidussource.howmuchmobile.maps.overlays;

import android.graphics.*;
import ar.com.solidussource.howmuchmobile.R;
import ar.com.solidussource.howmuchmobile.common.entities.Geopoint;
import ar.com.solidussource.howmuchmobile.common.entities.Market;
import ar.com.solidussource.howmuchmobile.common.utils.ClusterService;
import ar.com.solidussource.howmuchmobile.common.utils.MarketCluster;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 20/09/12
 * Time: 16:36
 * To change this template use File | Settings | File Templates.
 */
public class OverlayMap extends Overlay {

    private MarketCluster market;

    public OverlayMap(MarketCluster mc){
        market = mc;

    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow){

        ClusterService clusterService = new ClusterService();
        Geopoint gp = clusterService.getCluterGlobalPositioning(market);

        Projection projection = mapView.getProjection();
        GeoPoint geoPoint =
                new GeoPoint((int) gp.getLatitude(), (int) gp.getLongitude());

        if (shadow == false){

            Point centro = new Point();
            projection.toPixels(geoPoint, centro);

            //Definimos el pincel de dibujo
            Paint p = new Paint();
            p.setColor(Color.BLACK);
            p.setColor(R.color.celestial);

            p.setTextSize(16);

            Typeface tf = Typeface.create("Helvetica",Typeface.BOLD_ITALIC);
            p.setTypeface(tf);

            if(market.getMarkets().size() == 1){
                Iterator<Market> ite = market.getMarkets().iterator();
                canvas.drawText(ite.next().getMarketcategory().getName(), centro.x+0, centro.y+70, p);

                Bitmap bm = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.cart3);
                canvas.drawBitmap(bm, centro.x, centro.y, p);
            }
            else{
                canvas.drawText(Integer.toString(market.getMarkets().size()), centro.x+0, centro.y+0, p);

                Bitmap bm = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.cluster1);
                canvas.drawBitmap(bm, centro.x, centro.y, p);
            }


        }
    }
}
